﻿namespace S7.Net.Types
{
    using System;
    using System.Text;

    public static class String
    {
        private static int Asc(string s)
        {
            byte[] bytes = Encoding.ASCII.GetBytes(s);
            if (bytes.Length > 0)
            {
                return bytes[0];
            }
            return 0;
        }

        public static string FromByteArray(byte[] bytes)
        {
            return Encoding.ASCII.GetString(bytes);
        }

        public static byte[] ToByteArray(string value)
        {
            string str = value;
            char[] chArray = str.ToCharArray();
            byte[] buffer = new byte[str.Length];
            for (int i = 0; i <= (chArray.Length - 1); i++)
            {
                buffer[i] = (byte) Asc(chArray[i].ToString());
            }
            return buffer;
        }
    }
}

